package cn.edu.nju.freshdelivery.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import cn.edu.nju.freshdelivery.dao.SellerDAO;
import cn.edu.nju.freshdelivery.model.Seller;
import cn.edu.nju.freshdelivery.service.SellerService;

@Component
public class SellerServiceImpl implements SellerService {
	private SellerDAO sellerDAO;

	public SellerDAO getSellerDAO() {
		return sellerDAO;
	}

	@Resource
	public void setSellerDAO(SellerDAO sellerDAO) {
		this.sellerDAO = sellerDAO;
	}

	public void add(Seller seller) {
		sellerDAO.save(seller);
	}

	public List<Seller> findByAddress(String address) {
		return sellerDAO.findByAddress(address);
	}

	public List<Seller> findByValid(boolean valid) {
		return sellerDAO.findByValid(valid);
	}

	@Override
	public Seller findByUsername(String username) {
		if (sellerDAO.findByUsername(username).size() > 0)
			return sellerDAO.findByUsername(username).get(0);
		return null;
	}

}
